<?php

session_start();
if (!empty($_SESSION["userType"])) {
    $userType = $_SESSION["userType"];
}
if (!empty($_SESSION["centreName"])) {
    $centreName = $_SESSION["centreName"];
}

$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$searchid = isset($_POST['searchid']) ? mysql_real_escape_string($_POST['searchid']) : '';
$offset = ($page - 1) * $rows;
$result = array();

include 'conn.php';
   $rs1 = mysql_query("select count(*) from client  where CentreId is null");
    $row1 = mysql_fetch_row($rs1);
    $result1["total"] = $row1[0];
    $rs1 = mysql_query("SELECT NRIC, CustomerName, Citizenship, BeforeDeviation, AfterDeviation, DateOfBirth, Gender,  'Withdrawn' AS CentreName
		FROM client
		WHERE CentreId IS NULL AND (

		NRIC LIKE  '%$searchid%'
                    OR CustomerName LIKE '%$searchid%'
		OR Citizenship LIKE  '%$searchid%'
		OR BeforeDeviation LIKE  '%$searchid%'
		OR AfterDeviation LIKE  '%$searchid%'
		OR DateOfBirth LIKE  '%$searchid%'
		OR Gender LIKE  '%$searchid%'

		) limit $offset,$rows");


    $items1 = array();
    while ($row1 = mysql_fetch_object($rs1)) {
        array_push($items1, $row1);
    }

    $result["rows"] = $items1;

echo json_encode($result);
?>